package aerouacmsla.interfazDeUsuario;

import aerouacmsla.procedimientos.BDConexion;
import aerouacmsla.procedimientos.GeneradorIdes;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import aerouacmsla.entidad.Pasajero;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;

/**
 *
 * @author luis
 */
public class VentanaRegistroPasajero extends javax.swing.JDialog {

     Pasajero PasajeroActual = new Pasajero();
     private BDConexion miConexion;
     private int Anno;
     private int Mes;
     private int Dia;
     private JTabbedPane panelPadre;


    public VentanaRegistroPasajero() {
        initComponents();
        setModal(true);
        setComboAnno();
    }

    public JTabbedPane getPanelPadre() {
        return panelPadre;
    }

    public void setPanelPadre(JTabbedPane panelPadre) {
        this.panelPadre = panelPadre;
    }

    public int getAnno() {
        return Anno;
    }

    public void setAnno(int Anno) {
        this.Anno = Anno;
    }

    public int getDia() {
        return Dia;
    }

    public void setDia(int Dia) {
        this.Dia = Dia;
    }

    public int getMes() {
        return Mes;
    }

    public void setMes(int Mes) {
        this.Mes = Mes;
    }

    public void elegirNuevoRegistro(int index){
        getPanelPadre().setSelectedIndex(index);
    }

    private void reiniciarDatos() {
        Nombrepasajero.setText(null);
        Apellidopaternopasajero.setText(null);
        Apellidomaternopasajero.setText(null);
        Telefonopasajero.setText(null);
        RFCpasajero.setText(null);
        Correoelectronicopasajero.setText(null);
    }

    public JPanel getPanelPrincipalRegistroPasajero() {
        return panelPrincipalRegistroPasajero;
    }

    public void setPanelPrincipalRegistroPasajero(JPanel panelPrincipalRegistroPasajero) {
        this.panelPrincipalRegistroPasajero = panelPrincipalRegistroPasajero;
    }


     public VentanaRegistroPasajero(BDConexion miConexion) {
        initComponents();
        setModal(true);
        setComboAnno();
        setMiConexion(miConexion);
     }

     public VentanaRegistroPasajero(BDConexion miConexion, JTabbedPane panelPadre) {
        initComponents();
        setModal(true);
        setComboAnno();
        setMiConexion(miConexion);
        setPanelPadre(panelPadre);
     }

    public BDConexion getMiConexion() {
        return miConexion;
    }

    public void setMiConexion(BDConexion miConexion) {
        this.miConexion = miConexion;
    }

    public Pasajero getPasajeroActual() {
        return PasajeroActual;
    }

    public void setPasajeroActual(Pasajero PasajeroActual) {
        this.PasajeroActual = PasajeroActual;
    }
     public boolean separarFecha(String fechaCompleta){
        String[] separado = fechaCompleta.split("-");
        if (separado.length == 3) {
            setAnno(Integer.parseInt(separado[0]));
            setMes(Integer.parseInt(separado[1]));
            setDia(Integer.parseInt(separado[2]));
            return true;
        }
        return false;
    }

    public VentanaRegistroPasajero(Pasajero pasajero, BDConexion miConexion) {
        initComponents();
        setModal(true);
        setComboAnno();
        setMiConexion(miConexion);
        setPasajeroActual(pasajero);
        setComboAnno();


        Registrar.setText("Modificar");
        Nombrepasajero.setText(getPasajeroActual().getNombre());
        Apellidopaternopasajero.setText(getPasajeroActual().getApellidoPaterno());
        Apellidomaternopasajero.setText(getPasajeroActual().getApellidoMaterno());
        Telefonopasajero.setText(getPasajeroActual().getTelefono());
        RFCpasajero.setText(getPasajeroActual().getRfc());
        Correoelectronicopasajero.setText(getPasajeroActual().getCorreoElectronico());
        if(separarFecha(getPasajeroActual().getFechaDeNacimiento())){
            comboAnno.setSelectedItem(getAnno());
            comboMes.setSelectedIndex(getMes()-1);
            comboDia.setSelectedIndex(getDia()-1);
        }
        getPasajeroActual().setIdPasajero(pasajero.getIdPasajero());

    }
    public boolean validarTam (String cadena, int tamano){
        if(cadena.length()<=tamano){
            return false;
        }
        return true;
    }
        private void setComboAnno(){
        Calendar fecha = new GregorianCalendar();
        int annoActual = fecha.get(Calendar.YEAR);
        Object objetosComboAnno[] = null;
        for(int i=annoActual-18; i>=annoActual-35; i--){
            objetosComboAnno = addObject(objetosComboAnno, i);
        }
        comboAnno.setModel(new DefaultComboBoxModel(objetosComboAnno));
    }
         public Object[] addObject(Object objeto[], Object newObject){
        Object[] retorno = null;
        if (objeto != null ){
            retorno = new Object[objeto.length + 1];
            for(int i=0; i<objeto.length; i++){
                retorno[i] = objeto[i];
            }
        }
        else retorno = new Object[1];
        retorno[retorno.length-1] = newObject;
        return retorno;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelPrincipalRegistroPasajero = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        Nombrepasajero = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        Apellidopaternopasajero = new javax.swing.JTextField();
        Apellidomaternopasajero = new javax.swing.JTextField();
        comboDia = new javax.swing.JComboBox();
        comboMes = new javax.swing.JComboBox();
        comboAnno = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        Telefonopasajero = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        RFCpasajero = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        Correoelectronicopasajero = new javax.swing.JTextField();
        Registrar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cliente");
        setIconImage(new ImageIcon(getClass().getResource("/Recursos/IconoCliente32px.png")).getImage());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Campos Obligatorios"));

        jLabel1.setText("Nombre");

        jLabel2.setText("Apellido Paterno");

        comboDia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        comboMes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));
        comboMes.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboMesItemStateChanged(evt);
            }
        });

        comboAnno.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2010" }));
        comboAnno.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboAnnoItemStateChanged(evt);
            }
        });

        jLabel3.setText("Apellido Materno");

        jLabel4.setText("Fecha de nacimiento");

        jLabel5.setText("Telefono");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(Apellidopaternopasajero, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                        .addComponent(Apellidomaternopasajero)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(comboDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(comboMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(comboAnno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(Nombrepasajero, javax.swing.GroupLayout.Alignment.LEADING))
                    .addComponent(Telefonopasajero, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Nombrepasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Apellidopaternopasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Apellidomaternopasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboAnno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(Telefonopasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Campos opcionales"));

        jLabel18.setText("RFC");

        jLabel19.setText("Correo Electronico");

        Registrar.setText("REGISTRAR");
        Registrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                RegistrarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Correoelectronicopasajero, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                            .addComponent(RFCpasajero, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(Registrar)
                        .addGap(73, 73, 73))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(RFCpasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addComponent(Correoelectronicopasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                .addComponent(Registrar)
                .addGap(42, 42, 42))
        );

        javax.swing.GroupLayout panelPrincipalRegistroPasajeroLayout = new javax.swing.GroupLayout(panelPrincipalRegistroPasajero);
        panelPrincipalRegistroPasajero.setLayout(panelPrincipalRegistroPasajeroLayout);
        panelPrincipalRegistroPasajeroLayout.setHorizontalGroup(
            panelPrincipalRegistroPasajeroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPrincipalRegistroPasajeroLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12))
        );
        panelPrincipalRegistroPasajeroLayout.setVerticalGroup(
            panelPrincipalRegistroPasajeroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPrincipalRegistroPasajeroLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelPrincipalRegistroPasajeroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelPrincipalRegistroPasajero, javax.swing.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelPrincipalRegistroPasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void RegistrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RegistrarMouseClicked


         if(!Nombrepasajero.getText().isEmpty()&&
           !Apellidopaternopasajero.getText().isEmpty()&&
           !Telefonopasajero.getText().isEmpty()
           
          ){

              boolean excedecaracteres[] = {
                  validarTam(Nombrepasajero.getText(),15),
                  validarTam(Apellidopaternopasajero.getText(),15),
                  validarTam(Apellidomaternopasajero.getText(),15),
                  validarTam(Telefonopasajero.getText(),18),
                  validarTam(RFCpasajero.getText(),13),
                  validarTam(Correoelectronicopasajero.getText(),50)
              };

              if( excedecaracteres[0] || excedecaracteres[1] ||
                  excedecaracteres[2] || excedecaracteres[3] ||
                  excedecaracteres[4] || excedecaracteres[5] 
                   ){

            boolean someError = false;
            String mensajeDeError = "";
            if (excedecaracteres[0]){
                someError = true;
                mensajeDeError += "El campo 'Nombre' debe ser menor o igual a 12 caracteres\n";
                System.out.println("exede numero de caracteres en Nombre");
            }
            if (excedecaracteres[1]){
                someError = true;
                mensajeDeError += "El campo 'Apellido Paterno' debe ser menor o igual a 12 caracteres\n";
                System.out.println("exede numero de caracteres en Apellido Paterno");
            }
            if (excedecaracteres[2]){
                someError = true;
                mensajeDeError += "El campo 'Apellido Materno' debe ser menor o igual a 12 caracteres\n";
                System.out.println("exede numero de caracteres en Apellido Materno");
            }
            if (excedecaracteres[3]){
                someError = true;
                mensajeDeError += "El campo 'Telefono' debe ser menor o igual a 20 caracteres\n";
                System.out.println("exede numero de caracteres en Telefono");
            }
            if (excedecaracteres[4]){
                someError = true;
                mensajeDeError += "El campo 'RFC' debe ser menor o igual a 14 caracteres\n";
                System.out.println("exede numero de caracteres en RFC");
            }
            if (excedecaracteres[5]){
                someError = true;
                mensajeDeError += "El campo 'Correo Electronico' debe ser menor o igual a 50 caracteres\n";
                System.out.println("excede el numero de caracteres en Correo Electronico");
            }
            if (someError)
                JOptionPane.showMessageDialog(this,
                 mensajeDeError,
                 "Error de datos",
                 JOptionPane.ERROR_MESSAGE);

              }else{

                  getPasajeroActual().setNombre(Nombrepasajero.getText());
                  getPasajeroActual().setApellidoPaterno(Apellidopaternopasajero.getText());
                  getPasajeroActual().setApellidoMaterno(Apellidomaternopasajero.getText());
                  getPasajeroActual().setTelefono(Telefonopasajero.getText());
                  getPasajeroActual().setRfc(RFCpasajero.getText());
                  getPasajeroActual().setCorreoElectronico(Correoelectronicopasajero.getText());

                  getPasajeroActual().setFechaDeNacimiento(
                          comboAnno.getSelectedItem().toString() +
                          "-" + (comboMes.getSelectedIndex()+1)  +
                          "-" + comboDia.getSelectedItem().toString());
                  GeneradorIdes GI = new GeneradorIdes(getPasajeroActual().getNombre(), getPasajeroActual().getApellidoPaterno(), getPasajeroActual().getApellidoMaterno(), getPasajeroActual().getFechaDeNacimiento());
                  if (Registrar.getText().equalsIgnoreCase("Registrar")) {
                      PasajeroActual.setIdPasajero(GI.getId());
                      for (;;) {
                          try {
                              if (getMiConexion().sendSQLQuery("SELECT * FROM cliente WHERE id_cliente = '" + getPasajeroActual().getIdPasajero() + "';").next()) {
                                  PasajeroActual.setIdPasajero(GI.siguienteId());
                              } else {
                                  break;
                              }
                          } catch (SQLException ex) {
                              Logger.getLogger(PanelAdministrarCiudades.class.getName()).log(Level.SEVERE, null, ex);
                          }
                      }
                  }

            String SQL = null;
            if(Registrar.getText().equalsIgnoreCase("Registrar")){
                SQL = "INSERT INTO cliente VALUES ('"+getPasajeroActual().getIdPasajero() +"', '" +
                        getPasajeroActual().getNombre() +"' , '"+getPasajeroActual().getApellidoPaterno() +"','" +
                        getPasajeroActual().getApellidoMaterno()+"','"+getPasajeroActual().getTelefono() +"','"
                        +getPasajeroActual().getRfc() +"','"+getPasajeroActual().getCorreoElectronico()+"','"+
                        getPasajeroActual().getFechaDeNacimiento()+"');";
            }
            else{
                SQL = " UPDATE cliente SET nombre = '" +
                        getPasajeroActual().getNombre() +"' , apellido_paterno ='"+getPasajeroActual().getApellidoPaterno() +"', apellido_materno = '" +
                        getPasajeroActual().getApellidoMaterno()+"', telefono = '"+getPasajeroActual().getTelefono() +"', rfc = '"
                        +getPasajeroActual().getRfc() +"', correo_electronico = '"+getPasajeroActual().getCorreoElectronico()+"',  fecha_nacimiento = '"+
                        getPasajeroActual().getFechaDeNacimiento()+"' WHERE id_cliente = '" + getPasajeroActual().getIdPasajero() +"';";
            }
            getMiConexion().sendSQL(SQL);
            JOptionPane.showMessageDialog(this,
                 "El Cliente ha sido registrado exitosamente",
                 "Usuario Registrado Exitosamente",
                 JOptionPane.INFORMATION_MESSAGE);
            reiniciarDatos();
            elegirNuevoRegistro(0);
            this.dispose();
         }

        }else JOptionPane.showMessageDialog(this,
                 "Es necesario llenar todos los campos obligatorios",
                 "Error de datos",
                 JOptionPane.ERROR_MESSAGE);


    }//GEN-LAST:event_RegistrarMouseClicked

    private void comboMesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboMesItemStateChanged

    String mes = comboMes.getSelectedItem().toString();
        int diaSeleccionado = comboDia.getSelectedIndex();
        int mesInt = 0;
        if (mes.equalsIgnoreCase("enero"))
            mesInt = 1;
        else if (mes.equalsIgnoreCase("febrero"))
            mesInt = 2;
        else if (mes.equalsIgnoreCase("marzo"))
            mesInt = 3;
        else if (mes.equalsIgnoreCase("abril"))
            mesInt = 4;
        else if (mes.equalsIgnoreCase("mayo"))
            mesInt = 5;
        else if (mes.equalsIgnoreCase("junio"))
            mesInt = 6;
        else if (mes.equalsIgnoreCase("julio"))
            mesInt = 7;
        else if (mes.equalsIgnoreCase("agosto"))
            mesInt = 8;
        else if (mes.equalsIgnoreCase("septiembre"))
            mesInt = 9;
        else if (mes.equalsIgnoreCase("octubre"))
            mesInt = 10;
        else if (mes.equalsIgnoreCase("noviembre"))
            mesInt = 11;
        else if (mes.equalsIgnoreCase("diciembre"))
            mesInt = 12;
        Object dias[] = null;
        switch(mesInt){
            case 1:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 2:
                dias = null;
                int annio =  Integer.parseInt(comboAnno.getSelectedItem().toString());
                int biciesto = 28;
                if (annio%4 == 0) biciesto = 29;
                for (int i = 1; i <= biciesto; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 3:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 4:
                dias = null;
                for (int i = 1; i <= 30; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 5:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 6:
                dias = null;
                for (int i = 1; i <= 30; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 7:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 8:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 9:
                dias = null;
                for (int i = 1; i <= 30; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 10:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 11:
                dias = null;
                for (int i = 1; i <= 30; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 12:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
        }

    }//GEN-LAST:event_comboMesItemStateChanged

    private void comboAnnoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboAnnoItemStateChanged

         if (comboMes.getSelectedItem().toString().equalsIgnoreCase("febrero")){
            int diaSeleccionado = Integer.parseInt(comboDia.getSelectedItem().toString());
            Object[] dias = null;
            int annio = Integer.parseInt(comboAnno.getSelectedItem().toString());
            if (annio%4!=0) {
                for (int i=1; i<=28; i++){
                    dias = addObject(dias, i);
                }
            }
            else
                for (int i=1; i<=29; i++){
                    dias = addObject(dias, i);
                }
            comboDia.setModel(new DefaultComboBoxModel(dias));
            if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
        }
    }//GEN-LAST:event_comboAnnoItemStateChanged

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaRegistroPasajero().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Apellidomaternopasajero;
    private javax.swing.JTextField Apellidopaternopasajero;
    private javax.swing.JTextField Correoelectronicopasajero;
    private javax.swing.JTextField Nombrepasajero;
    private javax.swing.JTextField RFCpasajero;
    private javax.swing.JButton Registrar;
    private javax.swing.JTextField Telefonopasajero;
    private javax.swing.JComboBox comboAnno;
    private javax.swing.JComboBox comboDia;
    private javax.swing.JComboBox comboMes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel panelPrincipalRegistroPasajero;
    // End of variables declaration//GEN-END:variables
}
